package com.yungu.swift.system.sys.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.alicp.jetcache.anno.Cached;
import com.yungu.swift.base.ResponseData;
import com.yungu.swift.base.mapper.IMapper;
import com.yungu.swift.base.service.impl.BaseServiceImpl;
import com.yungu.swift.system.sys.dao.SysCityMapper;
import com.yungu.swift.system.sys.model.dto.SysCityDto;
import com.yungu.swift.system.sys.model.vo.CityVo;
import com.yungu.swift.system.sys.service.SysCityService;
import com.yungu.swift.utils.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;


/**
 * <p>
 * 城市信息业务逻辑接口实现类
 *
 * @author qfHan - Generate
 * @version 1.0.0-RELEASE
 * @since 2018-07-02 11:19
 */
@Service
public class SysCityServiceImpl extends BaseServiceImpl<SysCityDto> implements SysCityService {

    @Autowired
    private SysCityMapper sysCityMapper;

    @Override
    protected IMapper<SysCityDto> getMapper() {
        return sysCityMapper;
    }

    @Override
    public ResponseData<List<SysCityDto>> findCityByProvinceId(String provinceId, Boolean filterArea) {
        Map<String, Object> build = MapUtils.build(4);
        build.put("father", provinceId);
        build.put("filterArea", filterArea);
        return ResponseData.buildSuccessResponse(sysCityMapper.list(build));
    }

    @Cached(name = "jetCache:system:getCityUuidByName:",key = "#originCity",expire = 150)
    @Override
    public ResponseData<String> getCityUuidByName(String originCity) {
        return ResponseData.buildSuccessResponse(sysCityMapper.getCityUuidByName(originCity));
    }

    @Override
    public ResponseData<String> getCityUuidByAdCode(String adCode) {
        return ResponseData.buildSuccessResponse(sysCityMapper.getCityUuidByAdCode(adCode));
    }

    @Override
    public ResponseData<List<SysCityDto>> getOpenCities(Map<String, Object> map) {
        return ResponseData.buildSuccessResponse(sysCityMapper.getOpenCities(map));
    }

    @Override
    public ResponseData<String> getMaxCityNo(String cityNo) {
        return ResponseData.buildSuccessResponse(sysCityMapper.getMaxCityNo(cityNo));
    }

    @Override
    public ResponseData<List<CityVo>> findCityByBusinessType(Map<String, Object> map) {
        return ResponseData.buildSuccessResponse(sysCityMapper.findCityByBusinessType(map));
    }

    @Override
    public ResponseData<String> getCityUuidByMap(Map<String, Object> map) {
        return ResponseData.buildSuccessResponse(sysCityMapper.getCityUuidByMap(map));
    }
}